package com.lagou.controller;

import com.lagou.domain.PromotionSpace;
import com.lagou.domain.ResponseResult;
import com.lagou.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/PromotionSpace")
public class PromotionSpaceController {

    @Autowired
    PromotionSpaceService promotionSpaceService;

    /**
     * 查询所有广告位列表
     *
     * @return
     */
    @RequestMapping("/findAllPromotionSpace")
    public ResponseResult findAllPromotionSpace() {

        List<PromotionSpace> list = promotionSpaceService.findAllPromotionSpace();
        return new ResponseResult(true, 200, "获取全部广告位列表成功", list);
    }

    /**
     * 新增或修改广告位
     *
     * @param promotionSpace
     * @return
     */
    @RequestMapping("/saveOrUpdatePromotionSpace")
    public ResponseResult saveOrUpdatePromotionSpace(@RequestBody PromotionSpace promotionSpace) {

        String msg = null;
        if (promotionSpace.getId() == null) {

            promotionSpaceService.savePromotionSpace(promotionSpace);
            msg = "新增广告位";
        } else {

            promotionSpaceService.updatePromotionSpace(promotionSpace);
            msg = "修改广告位";
        }

        return new ResponseResult(true, 200, msg, null);
    }

    /**
     * 根据id查询广告位信息
     *
     * @param id 广告位id
     * @return
     */
    @RequestMapping("/findPromotionSpaceById")
    public ResponseResult findPromotionSpaceById(Integer id) {

        PromotionSpace promotionSpace = promotionSpaceService.findPromotionSpaceById(id);
        return new ResponseResult(true, 200, "查询广告位成功", promotionSpace);
    }


}
